package com.work.dyduser.base;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * @author Created by WZ on 2016/1/27
 */
public class BasePagerAdapter<T> extends PagerAdapter {
	private int mChildCount = 0;
	protected List<T> list;

	public BasePagerAdapter(List<T> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		mChildCount = getCount();
		super.notifyDataSetChanged();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}

	@Override
	public int getItemPosition(Object object) {
		if (mChildCount > 0) {
			mChildCount--;
			return POSITION_NONE;
		}
		return super.getItemPosition(object);
	}
}
